//package com.hhq.holoera.gateway.config;
//
//import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
//import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
//import com.alibaba.fastjson.JSON;
//import com.hhq.common.exception.BizCodeEnume;
//import com.hhq.common.utils.R;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.reactive.function.server.ServerResponse;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//@Configuration
//public class SentinelGatewayConfig {
//
//    //这个是Spring5的响应式编程
//    //GatewayCallbackManager
//    public SentinelGatewayConfig(){
//        GatewayCallbackManager.setBlockHandler(new BlockRequestHandler(){
//            //网关的限流了请求，就会调用此回调
//            @Override
//            public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable t) {
//                R error = R.error(BizCodeEnume.TOO_MANY_REQUEST.getCode(), BizCodeEnume.TOO_MANY_REQUEST.getMsg());
//                String errJson = JSON.toJSONString(error);
//                Mono<ServerResponse> body = ServerResponse.ok().body(Mono.just(errJson), String.class);
//                return body;
//            }
//        });
//    }
//}
